import { ApiCall } from "tsrpc";
import MailManage from "../../core/manage/MailManage";
import { ReqMailList, ResMailList } from "../../shared/api_client/mail/PtlMailList";

export default async function (call: ApiCall<ReqMailList, ResMailList>) {
    try {
        const { userId } = call.req;
        
        if (!userId) {
            return call.error('用户ID不能为空');
        }

        // 获取玩家邮件列表
        const mailList = await MailManage.pull(userId);
        
        // 获取邮件数量
        const mailCount = await MailManage.getMailCount(userId);

        call.succ({
            mails: mailList,
            count: mailCount
        });

    } catch (error) {
        console.error('获取邮件列表失败:', error);
        call.error('获取邮件列表失败');
    }
} 
